package h0717;

import java.util.*;
import java.util.regex.Pattern;

/**
  * @description 解密犯罪时间 使用dfs
  * @author 不知名帅哥
  * @date 2024/7/17 23:32
  * @version 1.0
*/
public class DecryptTimeCrime {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s = sc.next();
        String[] tmp = s.split(":");
        String hours=tmp[0];
        String minutes=tmp[1];

        System.out.println(getResult(tmp[0],tmp[1]));

    }

    private static String getResult(String hour,String minute) {
        HashSet<Character> set = new HashSet<>();
        for (int i = 0; i < hour.length(); i++) {
            set.add(hour.charAt(i));
        }
        for (int i = 0; i < minute.length(); i++) {
            set.add(minute.charAt(i));
        }
        Character[] arr=set.toArray(new Character[0]);

        ArrayList<String> res = new ArrayList<>();
        dfs(arr,new LinkedList<>(),res);

        res.sort(String::compareTo); //按照字典序排序
        int index= res.indexOf(hour+minute);

        String recentTime;
        if (index== res.size()-1){
            recentTime=res.get(0);
        }else {
            recentTime=res.get(index+1);
        }

        String[] split=recentTime.split("");
        split[1]+=":";
        return String.join("",split);
    }

    static Pattern p=Pattern.compile("(([01][0-9])|([2][0-3]))[0-5][0-9]");
    private static void dfs(Character[] arr, LinkedList<Character> path, ArrayList<String> res) {
        if (path.size()==4){
            StringBuilder sb=new StringBuilder();
            for (Character c:path){
                sb.append(c);
            }
            String timeStr=sb.toString();

            if (p.matcher(timeStr).find()){ //检查是否匹配合法的格式
                res.add(timeStr);
            }
            return;
        }

        for (Character c : arr) {
            path.add(c);
            dfs(arr,path,res);
            path.removeLast();
        }
    }
}
